var express = require('express');
var router = express.Router();
const userController = require('../controllers/user');

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

// 获取用户信息
router.get('/getUser', userController.showUser);

// 更新用户信息
router.post('/updateUser/:id', async (ctx) => {
  const { id } = ctx.params;
  const { name } = ctx.request.body;
  await knex('user').where('id', '=', id).update({ name });
  ctx.body = { message: `User ${id} updated` };
});

module.exports = router;
